package com.chenliwu.demo.java8.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author chenliwu
 * @since 2022-06-13
 */
public class CollectorsDemo {
    public static void main(String[] args) {
        testToList();

        testToSet();
    }

    private static void testToList() {
        List<String> stringList = Arrays.asList("aaa", "bbb", "ccc", "aaa", "bbb", "ccc");

        List<String> collect = stringList.stream().filter(str -> !str.isEmpty())
                .collect(Collectors.toList());
        System.out.println("collect = " + collect);
    }

    private static void testToSet() {
        List<String> stringList = Arrays.asList("aaa", "bbb", "ccc", "aaa", "bbb", "ccc");

        Set<String> collect = stringList.stream().filter(str -> !str.isEmpty())
                .collect(Collectors.toSet());
        System.out.println("collect = " + collect);
    }

}
